package com.reform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reform.config.JwtTokenUtil;
import com.reform.pojo.expert.ExpertScore;
import com.reform.pojo.expert.ViewExpertScore;
import com.reform.mapper.ViewExpertScoreMapper;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.IViewExpertScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author mortale
 * @since 2021-10-17
 */
@Service
public class ViewExpertScoreServiceImpl extends ServiceImpl<ViewExpertScoreMapper, ViewExpertScore> implements IViewExpertScoreService {

    @Autowired
    ViewExpertScoreMapper viewExpertScoreMapper;
    @Autowired
    JwtTokenUtil jwtTokenUtil;

    @Override
    public Result getExpertScoresByBatchId(String batchId, HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.failure(ResultCode.USER_AUTH_Login_LAPSE);
        }
        String gh = jwtTokenUtil.getGHFromToken(token);
        QueryWrapper<ViewExpertScore> qw = new QueryWrapper<>();
        qw.eq("expert_id", gh).eq("batch_id", batchId);
        List<ViewExpertScore> viewExpertScores = viewExpertScoreMapper.selectList(qw);
        return Result.success(ResultCode.SUCCESS, viewExpertScores);
    }
}
